package com.leetcode.No2580;

import org.junit.Test;

import java.util.Arrays;

public class Solution {
    public int countWays(int[][] ranges) {
        Arrays.sort(ranges, (x, y) -> {
            if (x[0] != y[0]) {
                return x[0] - y[0];
            } else {
                if (x[1] != y[1]) {
                    return x[1] - y[1];
                }
            }
            return 0;
        });
        int n = 1;
        int rangeMax = ranges[0][1];
        for (int i = 1; i < ranges.length; i++) {
            if (rangeMax < ranges[i][0]) {
                ++n;
                rangeMax = ranges[i][1];
            } else {
                rangeMax = Math.max(rangeMax, ranges[i][1]);
            }
        }
        int result = 1;
        for (int i = 0; i < n; i++) {
            result = (result<<1) % 1000000007;
        }
        return result;
    }

    @Test
    public void test() {
        int[][] ranges = {{34,56},{28,29},{12,16},{11,48},{28,54},{22,55},{28,41},{41,44}};
        System.out.println(countWays(ranges));
    }
}
